import 'package:flutter/material.dart';
import 'package:flutter_test_provider/providerDemo/counter_provider.dart';
import 'package:provider/provider.dart';

class SecondPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("第二个计数页面"),
      ),
      body: Consumer<CounterProvider>(
        builder: (ctx, counterPro, child) {
          print("consumer---builder---被调用");
          return Column(
            children: [
              child,
              RaisedButton(
                onPressed: () {
                  counterPro.counter += 1;
                },
                child: Text("+"),
              )
            ],
          );
        },
        child: MyText(),
      ),
      floatingActionButton: Consumer<CounterProvider>(
        builder: (ctx, counterPro, child) {
          print("consumer-floatingActionButton-builder---被调用");
          return FloatingActionButton(
              child: child,
              onPressed: () {
                counterPro.counter += 1;
              });
        },
        child: Icon(Icons.add),
      ),
    );
  }
}

class MyText extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    print("MyText:build");
    return Text("数量");
  }
}
